// https://leetcode.cn/problems/length-of-last-word/description/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    int lengthOfLastWord(string s) {
        int n = s.size();
        int i = n - 1, len = 0;
        while (i >= 0 && s[i] == ' ') i--; 
        while (i >= 0 && s[i] != ' ') {
            len++;
            i--;
        }
        return len;
    }
};